#include<bits/stdc++.h>
using namespace std;
int n,h[310],dp[310][310][310];
int dfs(int x,int y,int z){
    if(x>y)return 0;
    if(dp[x][y][z]!=-1)
        return dp[x][y][z];
    int as=0,uu=z,vv=n-((n-(y-x+1))-z)-1;
    as=max(dfs(x+1,y,z+1)+(h[x]==uu),dfs(x,y-1,z)+(h[y]==vv));
    as=max({as,dfs(x+1,y,z)+(h[x]==vv),dfs(x,y-1,z+1)+(h[y]==uu)});
    return dp[x][y][z]=as;
}
signed main(){
    freopen("build.in","r",stdin);
    freopen("build.out","w",stdout);
    memset(dp,-1,sizeof(dp));
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>h[i];
    dfs(1,n,1);
    cout<<n-dp[1][n][1]<<"\n";
    return 0;
}
